package com.weipai.education.controller;
import com.weipai.education.service.WeChatService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author: 曹朋飞
 * @Date: 2018/12/25 18:36
 */
@RestController
public class WxController {
    
    @Autowired
    private WeChatService wxService;

    /**
     * 授权
     * @return
     */
    @RequestMapping(value = "/wx/oauth2buildAuthorizationUrl", method = RequestMethod.GET)
    public String oauth2buildAuthorizationUrl(@RequestParam("returnUrl") String returnUrl){
        return wxService.oauth2buildAuthorizationUrl(returnUrl);
    }

    /**
     * 授权回调地址
     * @param code
     * @param returnUrl:/wx/getUserByOpenId
     * @return
     */
    @RequestMapping(value = "/wx/callBackUrl", method = RequestMethod.GET)
    public String callBackUrl(@RequestParam("code") String code,
                            @RequestParam("state") String returnUrl){
        return wxService.callBackUrl(code, returnUrl);
    }

    /**
     * 回调验证用户
     * @param openId
     * @return
     */
    @RequestMapping(value = "/wx/getUserByOpenId", method = RequestMethod.GET)
    public String getUserByOpenId(@RequestParam("openId") String openId){
        return wxService.getUserByOpenId(openId);
    }
}
